
* This file is a re-replication of Gibler, Miller, and Little replication of Weeks (2008). 
* This is the first of two Weeks replication files.
* It focuses on replicating how Weeks' dyads and recip variable were created.

clear
capture log close
cd "C:\Users\rum842\Dropbox\3.4 MID McManus\ISQ Response\Final Submission\Replication Files" //Insert your own directory here.
log using "Weeks Coding Replication.log", replace
set more off


* FIRST, REPLICATE HOW WEEKS CREATES HER DYADS AND RECIP VARIBLE, USING MID 3.02.

* Weeks used EUGene, so we are really replicating EUGene's process.

* Create dyads from MID 3.02, which Weeks used

use "MIDB 3.02.dta", clear
drop if sidea==0
ren * *a
ren dispnuma dispnum
save "temp.dta", replace

use "MIDB 3.02.dta", clear
drop if sidea==1
ren * *b
ren dispnumb dispnum

joinby dispnum using "temp.dta"

* Eliminate duplicates by collapsing

collapse (max) hostleva hostlevb, by(dispnum ccodea ccodeb)

* Make dyad ids for later merge

gen ccodehigh=ccodea if ccodea>ccodeb
replace ccodehigh=ccodeb if ccodeb>ccodea
gen ccodelow=ccodea if ccodea<ccodeb
replace ccodelow=ccodeb if ccodeb<ccodea
gen dyadid=ccodehigh*1000+ccodelow

save "Weeks Dyadic MIDs 3.02.dta", replace

* Use the incident-level data to make corrections.

* Create incident dyads

use "MIDIP 3.02.dta", clear
drop if sidea==0
ren * *a
ren dispnuma dispnum
ren incidnuma incidnum
save "temp.dta", replace

use "MIDIP 3.02.dta", clear
drop if sidea==1
ren * *b
ren dispnumb dispnum
ren incidnumb incidnum

joinby incidnum using "temp.dta"

* Make dyadid

gen ccodehigh=ccodea if ccodea>ccodeb
replace ccodehigh=ccodeb if ccodeb>ccodea
gen ccodelow=ccodea if ccodea<ccodeb
replace ccodelow=ccodeb if ccodeb<ccodea
gen dyadid=ccodehigh*1000+ccodelow

* Lay the groundwork for merging in dyadic hostility levels
* This is basically addressing the fact that MID participants may switch between sidea and sideb for different incidents.

gen ccodex=ccodea if ccodea<ccodeb //x means lower ccode
replace ccodex=ccodeb if ccodeb<ccodea
gen ccodey=ccodea if ccodea>ccodeb //y means higher ccode
replace ccodey=ccodeb if ccodeb>ccodea

gen hostlevx=hostleva if ccodex==ccodea
replace hostlevx=hostlevb if ccodex==ccodeb
gen hostlevy=hostleva if ccodey==ccodea
replace hostlevy=hostlevb if ccodey==ccodeb

sort dispnum dyadid ccodex ccodey
save "temp.dta", replace

collapse (max) hostlevx, by (dispnum dyadid ccodex) //This is identifying the max hostility level reached by the state with the lower ccode in each dyadic MID.
ren ccodex ccode
ren hostlevx hostlev
save "temp2.dta", replace

use "temp.dta", clear
collapse (max) hostlevy, by (dispnum dyadid ccodey) //This is identifying the max hostility level reached by the state with the higher ccode in each dyadic MID.
ren ccodey ccode
ren hostlevy hostlev
append using "temp2.dta" //This dataset now contains every country's max hostility level in each dyadic MID.
save "temp.dta", replace

* Merge the incident-corrected hostility levels back into the previous dataset

use "Weeks Dyadic MIDs 3.02.dta", clear

ren ccodea ccode
merge m:1 dispnum dyadid ccode using "temp.dta"
drop if _merge==2
drop _merge
ren ccode ccodea
replace hostleva=hostlev if hostlev!=.
drop hostlev

ren ccodeb ccode
merge m:1 dispnum dyadid ccode using "temp.dta"
drop if _merge==2
drop _merge
ren ccode ccodeb
replace hostlevb=hostlev  if hostlev!=.
drop hostlev

* Code recip variable

gen recip=(hostlevb>1)

save "Weeks Dyadic MIDs 3.02.dta", replace

* Open the original Weeks data (from her website) and prepare to merge

use "WeeksIO.dta", clear

* Change some variable names

ren cwinitnm dispnum
ren ccodecow ccodea
ren ccodecow2 ccodeb

* Create the recip variable using the exact code from Weeks' own do file

gen float recip=0
replace recip=1 if cwhost2>1

* Merge the two datasets together to confirm that what I did matches Weeks

merge 1:1 dispnum ccodea ccodeb using "Weeks Dyadic MIDs 3.02.dta", keepusing(recip) update replace

* Not sure why there is one unmatched observation in Weeks' data. It should not exist because both states are on Side A.
* However, we have perfectly replicated Weeks' recip coding.
* Therefore, this is the proper method for creating dyads and coding recip in order to replicate Weeks.
* We use this method below with different versions of the MID data.



* USE WEEKS' METHOD TO CREATE DYADS AND RECIP VARIABLE USING THE MID 4.3 DATA.

* MID 4.3 is the most recent official version of the MID data.

* Create dyads from MID 4.3

use "MIDB 4.3.dta", clear
drop if sidea==0
ren * *a
ren dispnum3a dispnum
save "temp.dta", replace

use "MIDB 4.3.dta", clear
drop if sidea==1
ren * *b
ren dispnum3b dispnum

joinby dispnum using "temp.dta"

* Eliminate duplicates by collapsing

collapse (max) hostleva hostlevb, by(dispnum ccodea ccodeb)

* Make dyad ids for later merge

gen ccodehigh=ccodea if ccodea>ccodeb
replace ccodehigh=ccodeb if ccodeb>ccodea
gen ccodelow=ccodea if ccodea<ccodeb
replace ccodelow=ccodeb if ccodeb<ccodea
gen dyadid=ccodehigh*1000+ccodelow

save "Weeks Dyadic MIDs 4.3.dta", replace

* Use the incident-level data to make corrections.

* Create incident dyads

use "MIDIP 4.3.dta", clear
drop if sidea==0
ren * *a
ren dispnum3a dispnum
ren incidnum3a incidnum3
save "temp.dta", replace

use "MIDIP 4.3.dta", clear
drop if sidea==1
ren * *b
ren dispnum3b dispnum
ren incidnum3b incidnum3

joinby incidnum3 using "temp.dta"

* Make dyadid

gen ccodehigh=ccodea if ccodea>ccodeb
replace ccodehigh=ccodeb if ccodeb>ccodea
gen ccodelow=ccodea if ccodea<ccodeb
replace ccodelow=ccodeb if ccodeb<ccodea
gen dyadid=ccodehigh*1000+ccodelow

* Lay the groundwork for merging in dyadic hostility levels

gen ccodex=ccodea if ccodea<ccodeb
replace ccodex=ccodeb if ccodeb<ccodea
gen ccodey=ccodea if ccodea>ccodeb
replace ccodey=ccodeb if ccodeb>ccodea

gen hostlevx=hostleva if ccodex==ccodea
replace hostlevx=hostlevb if ccodex==ccodeb
gen hostlevy=hostleva if ccodey==ccodea
replace hostlevy=hostlevb if ccodey==ccodeb

sort dispnum dyadid ccodex ccodey
save "temp.dta", replace

collapse (max) hostlevx, by (dispnum dyadid ccodex)
ren ccodex ccode
ren hostlevx hostlev
save "temp2.dta", replace

use "temp.dta", clear
collapse (max) hostlevy, by (dispnum dyadid ccodey)
ren ccodey ccode
ren hostlevy hostlev
append using "temp2.dta" //This dataset now contains every country's hostility level in each dyadic MID
save "temp.dta", replace

* Merge the incident-corrected hostility levels back into the previous dataset

use "Weeks Dyadic MIDs 4.3.dta", clear

ren ccodea ccode
merge m:1 dispnum dyadid ccode using "temp.dta"
drop if _merge==2
drop _merge
ren ccode ccodea
replace hostleva=hostlev if hostlev!=.
drop hostlev

ren ccodeb ccode
merge m:1 dispnum dyadid ccode using "temp.dta"
drop if _merge==2
drop _merge
ren ccode ccodeb
replace hostlevb=hostlev  if hostlev!=.
drop hostlev

* Code recip variable

gen recip=(hostlevb>1)

save "Weeks Dyadic MIDs 4.3.dta", replace


* USE WEEKS' METHOD TO CREATE DYADS AND RECIP VARIABLE USING GML DATA, VERSION 2.1

* We are using version 2.1 of the GML data, which is a later version than what is used in their article.
* We are doing this because GML incident-level data is not available prior to version 2.1
* Using incident-level data will allow for closer correspondence with Weeks' method of coding recip.

* Create dyads from GML MIDB 2.1

use "GML MIDB 2.1.dta", clear
drop if sidea=="NA"
destring sidea, replace
destring hostlev, replace
drop if sidea==0
ren * *a
ren dispnuma dispnum
save "temp.dta", replace

use "GML MIDB 2.1.dta", clear
drop if sidea=="NA"
destring sidea, replace
destring hostlev, replace
drop if sidea==1
ren * *b
ren dispnumb dispnum

joinby dispnum using "temp.dta"

* Eliminate duplicates by collapsing

collapse (max) hostleva hostlevb, by(dispnum ccodea ccodeb)

* Make dyad ids for later merge

gen ccodehigh=ccodea if ccodea>ccodeb
replace ccodehigh=ccodeb if ccodeb>ccodea
gen ccodelow=ccodea if ccodea<ccodeb
replace ccodelow=ccodeb if ccodeb<ccodea
gen dyadid=ccodehigh*1000+ccodelow

save "Weeks Dyadic MIDs GML 2.1.dta", replace

* Use the incident-level data to make corrections.

* Create incident dyads

use "GML MIDIP 2.1.dta", clear
drop if sidea==0
ren * *a
ren dispnum3a dispnum
ren incidnum3a incidnum3
save "temp.dta", replace

use "GML MIDIP 2.1.dta", clear
drop if sidea==1
ren * *b
ren dispnum3b dispnum
ren incidnum3b incidnum3

joinby incidnum3 using "temp.dta"

* Make dyadid

gen ccodehigh=ccodea if ccodea>ccodeb
replace ccodehigh=ccodeb if ccodeb>ccodea
gen ccodelow=ccodea if ccodea<ccodeb
replace ccodelow=ccodeb if ccodeb<ccodea
gen dyadid=ccodehigh*1000+ccodelow

* Lay the groundwork for merging in dyadic hostility levels

gen ccodex=ccodea if ccodea<ccodeb
replace ccodex=ccodeb if ccodeb<ccodea
gen ccodey=ccodea if ccodea>ccodeb
replace ccodey=ccodeb if ccodeb>ccodea

gen hostlevx=hostleva if ccodex==ccodea
replace hostlevx=hostlevb if ccodex==ccodeb
gen hostlevy=hostleva if ccodey==ccodea
replace hostlevy=hostlevb if ccodey==ccodeb

sort dispnum dyadid ccodex ccodey
save "temp.dta", replace

collapse (max) hostlevx, by (dispnum dyadid ccodex)
ren ccodex ccode
ren hostlevx hostlev
save "temp2.dta", replace

use "temp.dta", clear
collapse (max) hostlevy, by (dispnum dyadid ccodey)
ren ccodey ccode
ren hostlevy hostlev
append using "temp2.dta" //This dataset now contains every country's hostility level in each dyadic MID
save "temp.dta", replace

* Merge the incident-corrected hostility levels back into the previous dataset

use "Weeks Dyadic MIDs GML 2.1.dta", clear

ren ccodea ccode
merge m:1 dispnum dyadid ccode using "temp.dta"
drop if _merge==2
drop _merge
ren ccode ccodea
replace hostleva=hostlev if hostlev!=.
drop hostlev

ren ccodeb ccode
merge m:1 dispnum dyadid ccode using "temp.dta"
drop if _merge==2
drop _merge
ren ccode ccodeb
replace hostlevb=hostlev  if hostlev!=.
drop hostlev

* Code recip variable

gen recip=(hostlevb>1)

save "Weeks Dyadic MIDs GML 2.1.dta", replace


* USE WEEKS' METHOD TO CREATE DYADS AND RECIP VARIABLE USING GML DATA, ISQ VERSION

* We also replicate Weeks's data creation method using the older version of the GML data used in the ISQ article.
* With this dataset, it is not possible to make incident-level corrections, as Weeks did.
* However, it still would have been possible to more closely replicate Weeks' results with this dataset if GML had coded recip at the dyad level like Weeks, instead of the MID level.

* Create dyads from GML MIDB ISQ Version

use "GML MIDB ISQ.dta", clear
drop if sidea==0
ren * *a
ren dispnum3a dispnum
save "temp.dta", replace

use "GML MIDB ISQ.dta", clear
drop if sidea==1
ren * *b
ren dispnum3b dispnum

joinby dispnum using "temp.dta"

* Eliminate duplicates by collapsing

collapse (max) hostleva hostlevb, by(dispnum ccodea ccodeb)

* Code recip variable

gen recip=(hostlevb>1)

save "Weeks Dyadic MIDs GML ISQ.dta", replace


* USE GML METHOD TO CODE RECIP 

* We also replicate how GML coded recip to show that it is different from Weeks' method.

* First open GML replication file and delete observations that are missing values because otherwise these will interfere with the merge later.
* This file is available on Gibler's dataverse. We changed the name from WeeksIO to WeeksIO GML to distinguish it from Weeks' original replication data.

use "WeeksIO GML.dta", clear
drop if ccodecow==.
save "WeeksIO GML_ed.dta", replace

* Open Weeks' original IO replication file and relabel some variables.

use "WeeksIO.dta", replace
ren cwinitnm dispnum3
ren ccodecow ccodea
ren ccodecow2 ccodeb

* Merge in the MID-level recip variable from GML MIDA, ISQ verion
* Note that this variable is coded as 1 if any state on side B in the MID reciprocated. It is not adjusted for dyad.

merge m:1 dispnum3 using "GML MIDA ISQ.dta", keepusing(recip)
drop _merge
ren recip recip_gml_mida

* Confirm that this is the same way that GML coded recip by merging in GML's replication data file.

* Need to change some variable names back to accomplish this.
ren dispnum3 cwinitnm 
ren ccodea ccodecow 
ren ccodeb ccodecow2 

merge 1:1 cwinitnm ccodecow ccodecow2 using "WeeksIO GML_ed.dta", keepusing(new_recip) //new_recip is the variable GML add to Weeks' file to reflect their own coding.
drop _merge

* Compare the recip variable I just created with GML's "new_recip" variable.

tab recip_gml_mida new_recip

* This shows that recip and new_recip are a perfect match, except for one observation.
* Therefore, we have replicated GML's coding method and shown that it is different from Weeks.

* See how much of a difference this makes by merging in the dyadically coded variable based on GML MIDB ISQ version.

ren cwinitnm dispnum
ren ccodecow ccodea
ren ccodecow2 ccodeb

merge 1:1 ccodea ccodeb dispnum using "Weeks Dyadic MIDs GML ISQ.dta", keepusing(recip)
ren recip recip_gml_dyadic

* Compate the "new_recip" variable that GML used in their analysis with the dyadic version we created using GML MIDB ISQ version.

tab new_recip if _merge==3
tab recip_gml_dyadic if _merge==3

* Not surprisingly, GML's new_recip variable codes more reciprocations than our corrected version. 
* Incident-level corrections (would are impossible with the data used in GML's ISQ article) would make the difference even bigger.

 

